package echat.future.cn.echat.home;

import android.os.Bundle;
import android.util.Log;
import android.view.View;

import com.hyphenate.easeui.EaseConstant;
import com.hyphenate.easeui.EaseUI;
import com.hyphenate.easeui.domain.EaseUser;
import com.hyphenate.easeui.ui.EaseChatFragment;

import echat.future.cn.echat.R;
import echat.future.cn.echat.my.utils.UserHelper;
import lumingweihua.future.cn.baselibgxh.base.BaseActivity;
import lumingweihua.future.cn.baselibgxh.utils.Constant;
import lumingweihua.future.cn.baselibgxh.utils.SharedPreference;

/**
 * Created by Administrator on 2018/7/15.
 */

public class ChatActivity extends BaseActivity {

    @Override
    protected void initView() {
        setContentView(R.layout.activity_chat);
        initTitleBar(getIntent().getStringExtra("username"), Constant.DEFAULT_LEFT_BACK,null);

        EaseUI.getInstance().setUserProfileProvider(new EaseUI.EaseUserProfileProvider() {

            @Override
            public EaseUser getUser(String username) {
                Log.e("TAG", " username=" + username);
                EaseUser easeUser = new EaseUser(username);
                if(username.equals(SharedPreference.getString(context,"phone"))){
                    //自己的
                    easeUser.setAvatar(UserHelper.getUser().getAvatar());
                    easeUser.setNickname(UserHelper.getUser().getUsername());
                }else{
                    easeUser.setAvatar(getIntentExtra("avatar"));
                    easeUser.setNickname(getIntentExtra("username"));
                }

                return easeUser;
            }
        });

        //new出EaseChatFragment或其子类的实例
        EaseChatFragment chatFragment = new EaseChatFragment();
        //传入参数
        Bundle args = new Bundle();
        args.putInt(EaseConstant.EXTRA_CHAT_TYPE, EaseConstant.CHATTYPE_SINGLE);
        args.putString(EaseConstant.EXTRA_USER_ID, getIntentExtra("id"));
        chatFragment.setArguments(args);
        getSupportFragmentManager().beginTransaction().add(R.id.container, chatFragment).commit();

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void processClick(View v) {

    }
}
